package mh;


/**
 * Other players in the map use this Entity.<br>
 * 
 * @author Gianmarco
 * @see Entity
 * 
 */
public class OtherEntity extends Entity {

	private static long		lifePoints;
	private static int		level;
	private static long		experience;
	private static long		money;
	private static int		darkness;
	private static double	magicPower;
	private int				fireInterval;

	/** The frame duration in milliseconds, i.e. how long any given frame of animation lasts */
	private final long		animationFrameDuration	= VELOCITY / 3;
	/** The frame duration in milliseconds, i.e. how long any given frame of animation lasts */
	private final long		movementDelayDuration	= VELOCITY;

	/**
	 * Constructor of the Entity for each other player in the map.
	 * 
	 * @param sprite
	 *            The path of the sprite set.
	 * @param x
	 *            The X position of this <code>Entity</code> (tile unit)
	 * @param y
	 *            The Y position of this <code>Entity</code> (tile unit)
	 * @param plx
	 *            The X position of the <code>PlayerEntity</code> in the map (tile unit)
	 * @param ply
	 *            The X position of the <code>PlayerEntity</code> in the map (tile unit)
	 */
	public OtherEntity(String sprite, double x, double y, double plx, double ply) {
		super(sprite, x, y, plx, ply);
	}

	@Override
	public void draw(long delta) {
		if (!this.moving) {
			this.sprite.setFrame(1);
		} else {
			this.lastFrameChange += delta;
			if (this.lastFrameChange > this.animationFrameDuration) {
				this.lastFrameChange = 0;
				this.sprite.frameUp();
			}
		}
		this.sprite.draw(((this.actualX + CENTRAL_COLUMN) - this.playerX) * 32, ((this.actualY + CENTRAL_ROW) - this.playerY) * 32);
		this.lastStepChange += delta;
		if (this.lastStepChange > (this.movementDelayDuration / 2)) {
			this.lastStepChange = 0;
			if (this.actualX < this.finalX) {
				this.actualX += 0.5;
			} else if (this.actualX > this.finalX) {
				this.actualX -= 0.5;
			}
			if (this.actualY < this.finalY) {
				this.actualY += 0.5;
			} else if (this.actualY > this.finalY) {
				this.actualY -= 0.5;
			}
			if ((this.actualX == this.finalX) && (this.actualY == this.finalY)) {
				this.stop();
			}
		}

	}

	@Override
	public void move(long delta, int direction) {

		this.moving = true;
		this.sprite.setDirection(direction);
		this.lastMove += delta;
		if (this.lastMove > this.movementDelayDuration) {
			this.lastMove = 0;

			switch (direction) {
				case 0:
					this.finalY++;
					break;
				case 1:
					this.finalX--;
					break;
				case 2:
					this.finalX++;
					break;
				case 3:
					this.finalY--;
					break;
			}
		}
	}

	//	public void hitDamage(int value) {
	//		lifePoints -= value;
	//	}
	//
	//	public void collidedWith(EntityOld other) {
	//		if (other instanceof SpellEntity) {
	//			// tells the server I have been hit
	//			// oh, I have been hit
	//		}
	//	
	//	}
	//
	//	public void setFI(int i) {
	//		this.fireInterval = i;
	//	}
	//
	//	public int getFI() {
	//		return this.fireInterval;
	//	}

}
